package com.innerchic.huhu.http;

import android.util.Log;

import okhttp3.ResponseBody;

/**
 * ================================================
 * 作    者：贾恒飞 >>> 17515250730@163.com
 * 项    目：watcher-demo
 * 日    期：2021/12/17 15:13
 * 包    名：com.innerchic.communication.http
 * 描    述：请求回调代理
 * Create by zFox from AndroidStudio4.2
 * ================================================
 */
public class HttpCallbackProxy extends HttpCallback {

    private final String requestUrl;
    private final HttpCallback httpCallback;

    public HttpCallbackProxy(String requestUrl, HttpCallback httpCallback) {
        this.requestUrl = requestUrl;
        this.httpCallback = httpCallback;
    }

    @Override
    public void onSuccess(boolean isSuccess, ResponseBody body) {
        if (this.httpCallback != null) {
            this.httpCallback.onSuccess(isSuccess, body);
        }
    }

    @Override
    public void onError(String errorMessage) {
        if (this.httpCallback != null) {
            this.httpCallback.onError("请求[" + requestUrl + "]错误:" + errorMessage);
        }
    }

    @Override
    public void onAccident() {
        Log.d(TAG, "请求[" + requestUrl + "]超出预期的结果,空的回调Resp对象.");
        if (this.httpCallback != null) {
            this.httpCallback.onAccident();
        }
    }

    @Override
    public void onFailure(String failMessage) {
        if (this.httpCallback != null) {
            this.httpCallback.onFailure("[" + requestUrl + "] >>> " + failMessage);
        }
    }

}
